package com.xxl.job.kettle.core.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xxl.job.kettle.core.config.validate.UpdateGroup;
import com.xxl.job.kettle.result.Result;
//import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 实现功能：
 *
 * @author 作者[zk]
 * @version 1.0.00  2022-11-01 10:43
 */
@Validated
public class BaseController<T, S extends IService<T>> {

    @Autowired
    protected S service;

    @GetMapping("/getAllList")
//    @ApiOperation(value = "获取列表数据")
    public Result<List<T>> getAllList(){
        List<T> tList = service.getBaseMapper().selectList(new QueryWrapper<>());
        return Result.OK(tList);
    }

    @PostMapping("/save")
//    @ApiOperation(value = "保存配置")
    public Result<Boolean> save(@Validated @RequestBody T entity){
        boolean flag = service.save(entity);
        return Result.OK(flag);
    }

    @PostMapping("/modify")
//    @ApiOperation(value = "修改配置")
    public Result<Boolean> modify(@Validated(UpdateGroup.class) @RequestBody T entity){
        boolean flag = service.updateById(entity);
        return Result.OK(flag);
    }

    @GetMapping("/getById")
//    @ApiOperation(value = "通过id查询详细数据")
    public Result<T> getById(@NotEmpty(message = "id不能为空") @RequestParam String id){
        T t = service.getById(id);
        return Result.OK(t);
    }

//    @DeleteMapping("/delete")
//    @ApiOperation(value = "删除")
//    public Result<Boolean> delete(@NotEmpty(message = "id不能为空") @RequestParam String id){
//        boolean flag = service.removeById(id);
//        return Result.OK(flag);
//    }

}
